/**
 * 
 */
package com.thor.palmmall.rest.communicate.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.chart.converter.SDateRangeConverter;
import com.thor.palmmall.rest.communicate.ACommunicateQueryParam;
import com.thor.palmmall.spi.communicate.SCommunicateQueryParam;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class SCommunicateQueryParamConverter
    implements Converter<ACommunicateQueryParam, SCommunicateQueryParam> {

  public static SCommunicateQueryParamConverter getInstance() {
    if (instance == null)
      instance = new SCommunicateQueryParamConverter();
    return instance;
  }

  private static SCommunicateQueryParamConverter instance;

  private SCommunicateQueryParamConverter() {
  }

  @Override
  public SCommunicateQueryParam convert(ACommunicateQueryParam source) {
    if (source == null) {
      return null;
    }
    SCommunicateQueryParam target = new SCommunicateQueryParam();
    target.setBrand(UCN.newInstance(source.getBrand()));
    target.setDateRange(SDateRangeConverter.getInstance().convert(source.getDateRange()));
    target.setOrder(source.getOrder());
    target.setPage(source.getPage());
    target.setPageSize(source.getPageSize());
    target.setStores(new ArrayList<String>());
    target.getStores().addAll(source.getStores());
    target.setCounterpart(UCN.newInstance(source.getCounterpart()));
    target.setUserGroups(new ArrayList<KV>());
    target.getUserGroups().addAll(source.getUserGroups());
    target.setKeyword(source.getKeyword());
    return target;
  }

}
